package com.telit.firecommand.controller;

import com.telit.common.entity.DataReturn;
import com.telit.firecommand.dto.CommFireReportDTO;
import com.telit.firecommand.service.FireReportService;
import com.telit.firecommand.vo.CommFireReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

/**
 * Create by Chencf 2023/02/13
 */

@RestController
@RequestMapping("/fire-report")
@Api(tags = "火情报告相关接口", description = "/fire-report")
public class FireReportController {

    @Autowired
    private FireReportService fireReportService;



    @GetMapping("/findFireReport")
    @ApiOperation("/根据火情id查询火情报告")
    public DataReturn<CommFireReportVO> findFireReport(@RequestParam("fireId") String  fireId){
        CommFireReportVO vo = fireReportService.findFireReport(fireId);
        return DataReturn.ok(vo);
    }

    //
    @PostMapping("/updateFireReport")
    @ApiOperation("/更新火情报告")
    public DataReturn updateFireReport(@RequestBody CommFireReportDTO dto){
         fireReportService.updateFireReport(dto);
        return DataReturn.ok();
    }



    @ApiModelProperty("下载火情报告pdf")
    @GetMapping("/printDetailPDF")
    public void printDetailPDF(@RequestParam(value = "fireId") String  fireId, HttpServletRequest request, HttpServletResponse response) {
        response.reset();
        response.setContentType("application/pdf");
        try {
            OutputStream os = response.getOutputStream();
            fireReportService.printDetailPDF(fireId, os, request, response);
        } catch (Exception e) {
        }
    }
}
